package de.karlNet.gifSocket.servlets;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import de.karlNet.gifSocket.controllers.SessionController;
import de.karlNet.gifSocket.controllers.interfaces.ISessionController;

@Controller
@RequestMapping("/register_click_client")
public class RegisterClickClient {
	private static final long serialVersionUID = 1L;
	@Autowired
	private ISessionController sessionController;

	@RequestMapping("")
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		Integer sessionID = Integer
				.parseInt(request.getParameter("session_id"));
		this.sessionController.addMouseListener(sessionID,
				response.getOutputStream());
		
		response.setContentType("image/gif");
		response.setHeader("Cache-Control", "no-cache, no-store");
		response.setHeader("Pragma", "no-cache");
		Object o = new Object();
		try {
			synchronized (o) {
				o.wait();
			}
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}
